#include <ctime>
#include <iostream>
#include <string>
#include <asio.hpp>

using asio::ip::tcp;

std::string make_daytime_string()
{
    using namespace std;
    time_t now = time(0);
    return ctime(&now);
}

int main (int argc, char *argv[]) {
    try {
        asio::io_context io;

        tcp::acceptor acceptor(io, tcp::endpoint(tcp::v4(), 8888));

        for(;;) {
            tcp::socket socket(io);
            acceptor.accept(socket);

            std::string message = make_daytime_string();

            std::error_code ignored;
            asio::write(socket, asio::buffer(message), ignored); // best-effort
        }
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
